package com.algo.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import java.util.Arrays;

/**
 * Log切面类
 */
@Aspect
public class LogAspect {

    @Pointcut("execution(* com.algo.service.*.*(..))")
    public void LogAspect() {}

    @Before("LogAspect()")
    public void logBeforeBusiness(JoinPoint joinPoint) {
        System.out.println("业务方法执行前，记录日志：" + Arrays.toString(joinPoint.getArgs()));
    }

    @After("LogAspect()")
    public void logAftereBusiness(JoinPoint joinPoint) {
        System.out.println("业务方法执行结束，记录日志");
    }

    @AfterReturning(value = "LogAspect()", returning="result")
    public void logAfterReturn(JoinPoint joinPoint, Object result) {
        System.out.println("业务方法响应结果为：" + result);
    }

    @AfterThrowing(value = "LogAspect()", throwing = "exception")
    public void logInException(JoinPoint joinPoint, Exception exception) {
        System.out.println("业务方法执行异常：" + exception);
    }

}
